<?php 
	require_once('db.php');
	
	function getCategories()
        {
		return getCategoriesRec(1);
	}
	
	function getCategoriesRec($id)
        {
		$cats = DB::query("SELECT id, name FROM categories WHERE id = $id");
		$result = $cats[0];
		$categories = DB::query("SELECT id, name FROM categories WHERE parent_id = $id");
		$result['subCategories'] = array();
		foreach($categories as $key=>$category
                {
			array_push($result['subCategories'], getCategoriesRec($category["id"]));
		}
		return($result);
	}
?>